﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef G_PropertyWidget_H
#define G_PropertyWidget_H
#pragma once

#include "QtCommonWidget.h"

#include <QVBoxLayout>
#include <QFrame>
#include <QString>
#include <memory>

class QLabel;
class QPushButton;
class QEvent;
class QKeyEvent;

namespace PropertyWidget
{
    class CComponentTypeFilterWidget;
    class CComponentTypeFilter;
    class CComponentTypeWidget;
    class CComponentTypeItem;
    class CPropertyItem;
    class CInstancePropertyWidget;

    /*!
    *@class CPropertyWidget
    *@brief 属性面板窗口
    *
    */
    class QT_COMMON_WIDGET_EXPORT CPropertyWidget: public QFrame
    {
        Q_OBJECT
    public:
        /*!
        * @brief                                                 构造函数
        */
        explicit CPropertyWidget(QWidget* pParent = NULL);
        /*!
        * @brief                                                 析构函数
        */
        virtual ~CPropertyWidget();

        virtual bool eventFilter(QObject *object, QEvent *event) override;
      
    public:
        /*!
        * @brief      返回构件类型子窗口
        * @return     CComponentTypeWidget *
        */
        CComponentTypeWidget *GetComponentTypeWidget() const {return m_upTypeWidget.get();}
        /*!
        * @brief      返回属性实例子窗口
        * @return     CInstancePropertyWidget *
        */
        CInstancePropertyWidget *GetComponentInstancePropertyWidget() const {return m_upInstaceWidget.get();}
        

    protected slots:
        /*!
        *@brief       点击不同的构件类型触发的事件
        *@param [in] PropertyWidget::CComponentTypeItem * pComponentTypeItem
        *@return void
        */
        virtual void OnSelectComponentType(const CComponentTypeItem *pComponentTypeItem);
        /*!
        *@brief       编辑修改属性触发的事件
        *@param [in] int groupIndex
        *@param [in] int propertyIndex
        *@return void
        */
        virtual void OnPropertyValueChanged(int groupIndex, int propertyIndex);

        /*!
        * @brief      添加构件类型按钮点击回调
        * @return     void
        */
        virtual void OnAddComponentTypeBottonClick();
        /*!
        * @brief      编辑构件类型按钮点击回调
        * @return     void
        */
        virtual void OnModifyComponentBottonClick();
        /*!
        * @brief      应用按钮点击回调
        * @return     void
        */
        virtual void OnApply();

        /*!
        * @brief      当下拉列表收起,检查光标离开事件
        * @return     void
        */
        virtual void OnCheckLeaveEvent(QObject* obj);
Q_SIGNALS: 
        void mouseLeave();
        void sigPropertyBindButtonClicked(int uniqueId);
        void sigPropertyEditButtonClicked(int uniqueId);
        void DropDownListIndexChange(int groupIndex, int propertyIndex);

    protected:
        virtual void keyPressEvent(QKeyEvent *event) override;
        virtual void leaveEvent(QEvent *event) override;
        void setApplyButtonText(const QString& text);

        // 判断是否有属性修改发生
        bool IsPropertyValueChanged()const;

    private:
        void InitWidget();//初始化整体界面
        void InitTypeWidget();//初始化type
        void InitInstanceWidget();//初始化instance
        void InitApplyButton();//初始化applybutton
        bool IsAlphaKeys(int nChar); // 判断输入键是否为字母

    private:
        std::unique_ptr<QVBoxLayout>              m_upMainLayout;   //主布局
        std::unique_ptr<CComponentTypeWidget>     m_upTypeWidget;   //添加构件类别的类型
        std::unique_ptr<CInstancePropertyWidget>  m_upInstaceWidget;//添加构件实例
        std::unique_ptr<QPushButton>              m_upApplyButton;  //应用按钮
        std::unique_ptr<QHBoxLayout>              m_upButtonLayout; //按钮布局
        bool                                      m_isHotKeyPressed;//快捷键是否被按下
    };
}

#endif // G_PropertyWidget_H